<?php

namespace App\Http\Validate\OpenShop\Renew;

use App\Enums\OpenShop\InvestmentPromotion\ContractStatusEnum;
use App\Enums\OpenShop\InvestmentPromotion\UserContractEnum;
use App\Http\Validate\AbstractBaseValidate;
use App\Models\OpenShop\InvestmentPromotion\OpenShopSignOrderModel;
use App\Models\OpenShop\InvestmentPromotion\OpenShopUserContractModel;
use App\Models\OpenShop\Shop\OpenShopHandleExpireShopHistoryModel;
use App\Models\OpenShop\Shop\OpenShopHandleExpireShopMainModel;
use App\Models\Workflow\WorkflowOrderModel;
use Illuminate\Support\MessageBag;
use Illuminate\Validation\Rule;
use Illuminate\Validation\ValidationException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

class RenewValidate extends AbstractBaseValidate
{
    function getRules(): array
    {
        // TODO: Implement getRules() method.
        return [];
    }

    function getAttributes(): array
    {
        // TODO: Implement getAttributes() method.
        return [];
    }

    function registerValidateRules(): void
    {
        // TODO: Implement registerValidateRules() method.
    }

    function getMessages(): array
    {
        // TODO: Implement getMessages() method.
        return [];
    }

    /**
     * @param array $params
     * @return MessageBag|object
     * @throws ValidationException
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public static function deferOrderValidate(array $params = [])
    {
        return self::getInstance()->validate(
            ["orderNo", "date"],
            request()->merge($params)->all(),
            [
                "orderNo" => [
                    "required",
                    Rule::exists((new OpenShopSignOrderModel())->getTable(), "orderNo")
                ],
                "date"    => [
                    "required",
                    "string",
                    "date_format:Y-m-d"
                ]
            ]
        );
    }


    /**
     * @param array $params
     * @return MessageBag|object
     * @throws ValidationException
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public static function contractNoticeValidate(array $params = [])
    {
        return self::getInstance()->validate(
            ["workflowNo"],
            request()->merge($params)->all(),
            [
                "workflowNo" => [
                    "required",
                    "string",
                    Rule::exists((new OpenShopHandleExpireShopMainModel())->getTable(), "workOrderNo"),
                    Rule::exists((new WorkflowOrderModel())->getTable(), "workflowNo"),
                ]
            ]
        );
    }

    /**
     * @param array $params
     * @return MessageBag|object
     * @throws ValidationException
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public static function renewWorkOrderGroupListValidate(array $params = [])
    {
        return self::getInstance()->validate(
            ["pageNum", "pageSize", "type", "search"],
            request()->merge($params)->all(),
            [
                "pageNum"  => "required|int|min:1",
                "pageSize" => "required|int|min:1|max:100",
                "type"     => self::intInValidateBuild(true, OpenShopHandleExpireShopHistoryModel::TYPE_TEXT_GROUP),
                "search"   => "sometimes"
            ]
        );
    }

    /**
     * @param array $params
     * @return MessageBag|object
     * @throws ValidationException
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public static function renewWorkOrderFlowGroupListValidate(array $params = [])
    {
        return self::getInstance()->validate(
            ["pageNum", "pageSize", "type", "search"],
            request()->merge($params)->all(),
            [
                "pageNum"  => "required|int|min:1",
                "pageSize" => "required|int|min:1|max:100",
                "type"     => self::intInValidateBuild(true, OpenShopHandleExpireShopMainModel::FLOW_NODE_TEXT),
                "search"   => "sometimes"
            ]
        );
    }

    /**
     * @param array $params
     * @return MessageBag|object
     * @throws ValidationException
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public static function renewWorkOrderListValidate(array $params = [])
    {
        return self::getInstance()->validate(
            ["pageNum", "pageSize", "search"],
            request()->merge($params)->all(),
            [
                "pageNum"  => "required|int|min:1",
                "pageSize" => "required|int|min:1|max:100",
                "search"   => "sometimes"
            ]
        );
    }
}
